package com.kullachi.jmx.d3;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.management.MBeanAttributeInfo;
import javax.media.j3d.Appearance;
import javax.media.j3d.Material;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;

import com.sun.j3d.utils.geometry.Cone;
import com.sun.j3d.utils.image.TextureLoader;

public class MBeanAttributeInfo3D {
	Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    TransformGroup viewer;
    MBeanAttributeInfo attrInfo;
    
	public MBeanAttributeInfo3D(MBeanAttributeInfo info){
		super();
		this.attrInfo	= info;
	}

	public TransformGroup getViewer(Transform3D transform, Object value) {
		Appearance app = new Appearance();
		Color3f objColor = new Color3f(Color.DARK_GRAY);
		app.setMaterial(new Material(objColor, black, objColor, white, 80.0f));

		// Create name base image
		BufferedImage image = new BufferedImage(50, 50,
				BufferedImage.TYPE_INT_RGB);
		Graphics g = image.getGraphics();

		// create a rectangle filled with the color white:
		g.setColor(new Color(50, 150, 50));
		g.fillRect(0, 0, 50, 50);

		// add some text
		//g.setColor(Color.RED);
		//g.drawString(attrInfo.getName(), 20, 20);
		app.setTexture(new TextureLoader(image).getTexture());
		Cone cone = new Cone(1.0f, 2.0f, Cone.GENERATE_NORMALS
				| Cone.GENERATE_TEXTURE_COORDS, app);

		viewer = new TransformGroup(transform);

		if(value !=null){
			/*Font3D font3D = new Font3D(new Font("Arial", Font.PLAIN, 1),
					new FontExtrusion());
			Text3D textGeom = new Text3D(font3D, value.toString(),new Point3f(-0.8f,-0.8f,0.0f),);
			textGeom.setAlignment(Text3D.ALIGN_FIRST);
			Shape3D textShape = new Shape3D();
			textShape.setGeometry(textGeom);
			viewer.addChild(textShape);*/
		}
		viewer.addChild(cone);

		return viewer;
	}
}
